from PyQt5.QtWidgets import QWidget, QGridLayout, QListWidget, QPushButton

from modules.system import CompKabSolutionWindow, user


class KnownHostsManagement(CompKabSolutionWindow):
    def __init__(self):
        super().__init__()

        grid = QGridLayout()
        self.setLayout(grid)
        list_of_known_hosts = QListWidget()
        try:
            with open(f'/home/{user}/.ssh/known_hosts', 'r') as inp:
                lines = inp.readlines()
                known_hosts = [s.split()[0] for s in lines]
        except FileNotFoundError:
            known_hosts = []
        list_of_known_hosts.addItems(known_hosts)
        list_of_known_hosts.setSelectionMode(QListWidget.ExtendedSelection)
        grid.addWidget(list_of_known_hosts, 0, 0, 1, 2)
        btn1 = QPushButton("Кнопка 1")
        btn2 = QPushButton("Кнопка 2")
        grid.addWidget(btn1, 1, 0)
        grid.addWidget(btn2, 1, 1)

        self.setWindowTitle("Импорт известных хостов")
        self.setMinimumWidth(400)
        # self.show()
